﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GrewalCRM.Entities.Common;
using GrewalCRM.Entities;
using GrewalCRM.DAL;


namespace GrewalCRM.BLL
{
  public class ACBrands_BLL : BaseBLLGrewalCRM//, IBaseBLLGrewalCRM
  {
    public ACBrands_BLL()
    {
      baseDAL = new ACBrands_DAL();
    }

    #region Public Methods
    public List<ACBrands> GetAllACBrands()
    {
      List<BaseEntitiesGrewalCRM> baseEnttities = this.GetAll();
      List<ACBrands> CallStatuses = new List<ACBrands>();

      if (baseEnttities != null && baseEnttities.Count > 0)
      {
        foreach (BaseEntitiesGrewalCRM baseEntity in baseEnttities)
        {
          CallStatuses.Add(baseEntity as ACBrands);
        }
      }

      return CallStatuses;
    }

    public ACBrands GetACBrandByID(int ACBrandID)
    {
        BaseEntitiesGrewalCRM baseEntity = this.GetByID(ACBrandID);

        if (baseEntity != null)
            return baseEntity as ACBrands;
        else
            return null;
    }

    public void FillACBrand(ACBrands Entity)
    {
        FillEntity(Entity);

    }
    
    public int Save(ACBrands Entity)
    {
      int result = 0;
      EntityState state = EntityState.Nutral;

      if (Entity.ID == 0)
        state = EntityState.New;      
      else if (Entity.IsMarkedDeleted)
        state = EntityState.Deleted;
      else if (Entity.IsChanged)
        state = EntityState.Changed;

      switch (state)
      {
        case EntityState.New:
          result = AddNew(Entity);
          break;
        case EntityState.Deleted:
          result = Delete(Entity);
          break;
        case EntityState.Changed:
          result = Update(Entity);
          break;        
        default:
          result = 0;
          break;

      }

      return result;

    }

    protected override int AddNew(BaseEntitiesGrewalCRM Entity)
    {
      return baseDAL.AddNew(Entity);
    }

    protected override int Update(BaseEntitiesGrewalCRM Entity)
    {
      return baseDAL.Update(Entity);
    }

    protected override int Delete(BaseEntitiesGrewalCRM Entity)
    {
      return baseDAL.Delete(Entity);
    } 

    protected override List<BaseEntitiesGrewalCRM> GetAll()
    {
      return baseDAL.GetAll();
    }

    protected override BaseEntitiesGrewalCRM GetByID(int ID)
    {
      throw new NotImplementedException();
    }

    protected override void FillEntity(BaseEntitiesGrewalCRM Entity)
    {

        ACBrands tempACBrand = (baseDAL.GetByID(Entity.ID)) as ACBrands;

        ACBrands sourceACBrand = Entity as ACBrands;


        if (tempACBrand != null && sourceACBrand != null)
        {
            sourceACBrand.ID = tempACBrand.ID;
            sourceACBrand.ACBrandName = tempACBrand.ACBrandName;
            sourceACBrand.Description = tempACBrand.Description;
            sourceACBrand.IsActive = tempACBrand.IsActive;
            sourceACBrand.LastModifiedDateTime = tempACBrand.LastModifiedDateTime;
            sourceACBrand.LastModifiedUser = tempACBrand.LastModifiedUser;
        }
    } 
    #endregion
  }
}
